﻿using UnityEngine;
using System.Collections;

public class move : MonoBehaviour
{

    public Animation Any;
    RaycastHit Hit;

    float MoveSpeed;

    Vector3 Click;

    // Use this for initialization
    void Start()
    {
        MoveSpeed = 5f;
        Any.CrossFade("idle", 0.25f);
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {	//왼쪽 버튼 누르
            Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out Hit);

            Click = Hit.point; // 히트된 부분을 가져와서 클릭에 저
            Click.y = 0;

            transform.Translate((Click - transform.position).normalized * MoveSpeed * Time.deltaTime);
            Any.CrossFade("walk", 0.25f);
        }
        else
            Any.CrossFade("idle", 0.25f);
    }
}
